﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using BKH.BLL;

namespace BKH.MyUserControl.UCHienThi
{
    public partial class ucSuaThongTinBN : UserControl
    {
        int idBN;
        public ucSuaThongTinBN(int id)
        {
            InitializeComponent();
            this.idBN = id;
            showBN();
        }

        private void label3_Click(object sender, EventArgs e)
        {

        }

        void showBN()
        {
            BenhNhanBUO bn = new BenhNhanBUO();
            tbl_BenhNhan obj = new tbl_BenhNhan();
            var list = bn.GetSingle(idBN);
            txtFirstName.Text = list.FirstName;
            txtLastName.Text = list.LastName;
            txtCMND.Text = list.CMND;
            txtBirthday.Text = list.Birthday;
            txtBHYT.Text = list.BHYT;
            txtAddress.Text = list.Address;
            txtTel.Text = list.Tel;
            cbbMaritalStatus.Text = list.MaritalStatus;
            cbbSex.Text = list.Sex;

        }

        private void btnUpdate_Click(object sender, EventArgs e)
        {
            try
            {
                BenhNhanBUO bn = new BenhNhanBUO();
                tbl_BenhNhan obj = bn.GetSingle(idBN);
                var list = bn.GetSingle(idBN);
                obj.DateRegistered = list.DateRegistered;
                obj.FirstName = txtFirstName.Text;
                obj.LastName = txtLastName.Text;
                obj.Address = txtAddress.Text;
                obj.Sex = cbbSex.Text;
                obj.Tel = txtTel.Text;
                obj.MaritalStatus = cbbSex.Text;
                obj.BHYT = txtBHYT.Text;
                obj.CMND = txtCMND.Text;

                if (bn.Update(idBN, obj) == true)
                {

                    MessageBox.Show("Sửa thành công", "Thông báo");

                }
                else
                {
                    MessageBox.Show("Sửa ko thành công", "Thông báo");
                }
            }
            catch { MessageBox.Show("Sửa ko thành công", "Thông báo"); }

        }

        private void llbBck_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            UCHienThiDanhSachBN ds = new UCHienThiDanhSachBN();
            ControlAcess.ShowConTrol(this.ParentForm, ds, "gbHienThi");
        }
    }
}
